package langManagement;

import java.io.Serializable;
import java.util.Locale;
import java.util.Map;
import javax.faces.context.FacesContext;
import logManagement.Log4k;

/**
 *
 * @author ubuntu4ldl
 */
public class LanguagesBean implements Serializable{
    private Locale locale;
    
    public Locale getLocale() {
        return locale;
    }
    
    public void setLocale(Locale locale) {
        this.locale = locale;
    }
    
    public String changeLanguage() {
        FacesContext ctx = FacesContext.getCurrentInstance();
        Map<String, String> parameters = ctx.getExternalContext().getRequestParameterMap();
        String localeStr = parameters.get("locale");
        
        if (localeStr != null) {
            Locale newLocale = new Locale(localeStr);
            // ctx.getApplication().setDefaultLocale(newLocale); // change the locale
            ctx.getViewRoot().setLocale(newLocale);
            setLocale(newLocale);
            // ctx.renderResponse();
            return "success";
        } else {
            Log4k.warn(LanguagesBean.class.getName(), "missing request parameter 'locale'");
            return "missingParam";
        }
    }
    
}
